package com.dongliu.service.impl;

import com.dongliu.dao.BookDao;
import com.dongliu.domain.Book;
import com.dongliu.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookDao bookDao;

    public boolean save(Book book) {
        return bookDao.save(book) > 0;
    }

    public boolean update(Book book) {
        return bookDao.update(book) > 0;
    }

    public boolean delete(Integer id) {
        return bookDao.delete(id) > 0;
    }

    public Book getById(Integer id) {
        return bookDao.getById(id);
    }

    public List<Book> getBooks(String field) {
        field = "%" + field + "%";
        return bookDao.getBooks(field);
    }

//    public List<Book> getByName(String name) {
//        name = "%"+name+"%";
//        return bookDao.getByName(name);
//    }
//
//    public List<Book> getByType(String type) {
//        type = "%" + type + "%";
//        System.out.println(type);
//        return bookDao.getByType(type);
//    }
//
//    public List<Book> getByDescription(String description) {
//        description = "%" + description + "%";
//        return bookDao.getByDescription(description);
//    }



    public List<Book> getAll() {
        return bookDao.getAll();
    }

    public int getCount(){
        return bookDao.getCount();
    }
}

